Imports Aricie.DNN.UI.Controls

Namespace Aricie.DNN.Modules.LuceneSearch.UI
    Partial Public Class FuzzyFilter
        Inherits AricieUserControlBase

#Region "Event Handlers"

        Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
            If Not Me.IsPostBack Then
                Me.BindLayout()
                Me.ManageVisibility()
            End If
        End Sub

        Protected Sub chkApplyFuzzy_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) _
            Handles chkApplyFuzzy.CheckedChanged
            ManageVisibility()
        End Sub


#End Region


#Region "Public properties"

        Public Property ShowEnable() As Boolean
            Get
                Return Me.trEnabled.Visible
            End Get
            Set(ByVal value As Boolean)
                Me.trEnabled.Visible = value
            End Set
        End Property

        Public Property ShowLabel() As Boolean
            Get
                Return Me.tdLabel.Visible
            End Get
            Set(ByVal value As Boolean)
                Me.tdLabel.Visible = value
            End Set
        End Property

        Public Property FuzzyRatio() As Double
            Get
                Return Single.Parse(Me.ddlFuzzyRatio.SelectedValue)
            End Get
            Set(ByVal value As Double)
                Me.ddlFuzzyRatio.SelectedValue = value.ToString
                If value = 1 Then
                    Me.chkApplyFuzzy.Checked = False
                Else
                    Me.chkApplyFuzzy.Checked = True
                End If
                Me.ManageVisibility()
            End Set
        End Property

        Public Function HasRatio() As Boolean
            Return Not Me.chkApplyFuzzy.Checked AndAlso Double.Parse(Me.ddlFuzzyRatio.SelectedValue) <> 1
        End Function

#End Region

#Region "Private methods"

        Private Sub ManageVisibility()
            If Me.chkApplyFuzzy.Checked OrElse Not Me.ShowEnable Then
                Me.divFuzzyRatio.Visible = True
            Else
                Me.divFuzzyRatio.Visible = False
            End If
        End Sub

        Private Sub BindLayout()

            For i As Integer = 100 To 5 Step -5
                ddlFuzzyRatio.Items.Add(New ListItem(i.ToString & " %", (i / 100).ToString))
            Next
            Me.ddlFuzzyRatio.SelectedIndex = 0

        End Sub

#End Region
    End Class
End Namespace
